import React ,{ Component }from 'react';
import { connect } from 'react-redux';
import { renderRoutes } from 'react-router-config';
import {withRouter,Redirect} from 'react-router-dom';
import * as actionCreators from '../../store/actionCreators';
import CMenu from '../../comoponents/c-menu';
import CHeader from '../../comoponents/c-header';
import './index.scss';

class Index extends Component {
    constructor(props) {
        super(props);
        this.state = {
            route: props.route
        }
    }
    componentDidMount() {
        console.log(this.props.loginUser)
    }

    render() {
        return (
            <div className="main">
                <div className="menu-wrapper">
                    <div className="logo">
                        <img src={require("../../common/images/logo.png")} alt=""/>
                    </div>
                    <CMenu></CMenu>
                </div>
                <div className="right">
                    <div className="header">
                        <CHeader></CHeader>
                    </div>
                    <div className="container">
                        <Redirect exact to={this.props.route.children[0].path} from='/' />
                        {renderRoutes(this.props.route.children)}
                    </div>
                </div>
            </div>
        );
    }
}
const mapStateToProps = (state) => {
    return {
        loginUser: state.get('loginUser')
    }
}

const mapDispatchToProps = (dispatch) => ({
    setLoginUser(data) {
        const action = actionCreators.getLoginUser(data);
        dispatch(action);
    }
})
export default connect(mapStateToProps,mapDispatchToProps)(withRouter(Index))
